﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DeviceInfoManage.BusinessLogicLayer;
using System.Text;

public partial class MaintRecordStatistics : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*对进行查询的设备类型下拉框各项进行设置*/
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("logout.aspx");
            }

            DataSet ds = (new maintRecordInfo()).GetList();
            ddlErrType.DataSource = ds;
            ddlErrType.DataTextField = "errTypeName";
            ddlErrType.DataValueField = "errTypeName";
            ddlErrType.DataBind();
            ddlErrType.Items.Insert(0, new ListItem("=全部=", ""));

            ds = (new MaintPerson()).GetMaintPersonName();
            ddlPrincipal.DataSource = ds;
            ddlPrincipal.DataTextField = "maintPersonName";
            ddlPrincipal.DataValueField = "maintPersonName";
            ddlPrincipal.DataBind();
            ddlPrincipal.Items.Insert(0, new ListItem("全部", ""));

            Btn_Query_Click(null, null);
        }


    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标选择某行时变颜色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
        }
    }

    protected void Btn_Query_Click(object sender, EventArgs e)
    {
        StringBuilder strSql = new StringBuilder();
        int i = 0, j = 0, k = 0;
        if (!string.IsNullOrEmpty(ddlPrincipal.SelectedValue)) { strSql.Append(" AND maintPersonName = '" + ddlPrincipal.SelectedValue + "'"); i = 1; }
        if (!string.IsNullOrEmpty(txtDate1.Text)) { strSql.Append(" AND maintTime >= convert(datetime, '" + txtDate1.Text + "')"); }
        if (!string.IsNullOrEmpty(txtDate2.Text)) { strSql.Append(" AND maintTime <= convert(datetime, '" + txtDate2.Text + "')"); }
        if (!string.IsNullOrEmpty(ddlErrType.SelectedValue)) { strSql.Append(" AND errTypeName = '" + ddlErrType.SelectedValue + "'"); j = 1; }
        if (i == 0)
        {
            if (j == 0)
            {
                k = 4;
            }
            else
            {
                k = 3;
            }
        }
        else
        {
            if (j == 0)
            {
                k = 2;
            }
            else
            {
                k = 1;
            }
        }
        //this.GridView1.DataSourceID = null;
        this.GridView1.DataSource = (new maintRecordInfo()).DeviceStatistics(strSql.ToString());
        this.GridView1.DataBind();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Btn_Query_Click(null, null);
    }
}
